package com.arrogames.blondbattle.ui.buttons 
{
	import com.arrogames.blondbattle.assets.AssetManager;
	import feathers.controls.Button;
	import feathers.controls.ToggleSwitch;
	import feathers.skins.SmartDisplayObjectStateValueSelector;
	import starling.events.Event;
	import starling.textures.Texture;
	
	/**
	 * ...
	 * @author ...
	 */
	public class MusicButton extends Button {
		
		public static const MUTE:String = "mute";
		public static const UNMUTE:String = "unmute";
		
		public function MusicButton(muted:Boolean=false) {
			super();
			isToggle = true;
			isSelected = muted;
			
			var skinSelector:SmartDisplayObjectStateValueSelector = new SmartDisplayObjectStateValueSelector();
			skinSelector.defaultValue  = AssetManager.instance.getTexture("MusicOn");
			skinSelector.defaultSelectedValue = AssetManager.instance.getTexture("MusicOff");
			stateToSkinFunction = skinSelector.updateValue;
			
			this.width = 80;
			this.height = 80;
			
			this.addEventListener(Event.TRIGGERED, onToggle);
		}
		
		private function onToggle(e:Event):void {
			if (!isSelected) {
				dispatchEventWith(MUTE, true);
			} else {
				dispatchEventWith(UNMUTE, true);
			}
		}
		
	}

}